package com.example.lianxi222;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;
import android.view.MenuItem;

import com.example.lianxi222.adapter.Vp2Adapter;
import com.example.lianxi222.databinding.ActivityMainBinding;
import com.example.lianxi222.fragment.HomeFragment;
import com.example.lianxi222.fragment.MessageFragment;
import com.example.lianxi222.fragment.MineFragment;
import com.example.lianxi222.fragment.VideoFragment;
import com.example.mvvm_base.view.BaseSimpleView;
import com.example.mvvm_base.view.BaseView;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseSimpleView<ActivityMainBinding> {
private Vp2Adapter vp2Adapter;
private List<Fragment> list=new ArrayList<>();

    @Override
    protected void initData() {
        list.clear();
        list.add(new HomeFragment());
        list.add(new VideoFragment());
        list.add(new MessageFragment());
        list.add(new MineFragment());
     vp2Adapter=new Vp2Adapter(this,list);
     viewBinding.mainVp2.setAdapter(vp2Adapter);
    }

    @Override
    protected void initControlView() {
     viewBinding.mainBottom.setOnNavigationItemSelectedListener(item -> {
         switch (item.getItemId()){
             case R.id.home:
                 viewBinding.mainVp2.setCurrentItem(0);
                 break;
             case R.id.video:
                 viewBinding.mainVp2.setCurrentItem(1);
                 break;
             case R.id.start:

                 break;
             case R.id.message:
                 viewBinding.mainVp2.setCurrentItem(2);
                 break;
             case R.id.mine:
                 viewBinding.mainVp2.setCurrentItem(3);
                 break;

         }
         return true;
     });
     viewBinding.mainVp2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
         @Override
         public void onPageSelected(int position) {
             super.onPageSelected(position);
             switch (position){
                 case 0:
                     viewBinding.mainBottom.getMenu().getItem(0).setChecked(true);
                 break;
                 case 1:
                     viewBinding.mainBottom.getMenu().getItem(1).setChecked(true);
                     break;
                 case 2:
                     viewBinding.mainBottom.getMenu().getItem(3).setChecked(true);
                     break;
                 case 3:
                     viewBinding.mainBottom.getMenu().getItem(4).setChecked(true);
                     break;

             }

         }
     });
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }


}